//
//  XZAccoutnModel.m
//  XZIBeeBo
//
//  Created by Sean on 16/4/7.
//  Copyright © 2016年 XZSean. All rights reserved.
//

#import "XZAccoutnModel.h"

@interface XZAccoutnModel()<NSCoding>

@end

@implementation XZAccoutnModel

- (instancetype)initWithAccoutnModelDict:(NSDictionary *)dict{
 
    if (self = [super init]) {
        
//        self.access_token = dict[@"access_token"];
//        self.expires_in   = dict[@"expires_in"];
//        self.uid          = dict[@"uid"];
        [self setValuesForKeysWithDictionary:dict];
        //获得当前账号产生时间access_token获得时间
        self.created_time = [NSDate date];
    }
    return self;
}

+ (instancetype)accoutnModelWithDict:(NSDictionary *)dict{

    return [[self alloc] initWithAccoutnModelDict:dict];
}

/**
 *  当一个对象归档进入沙盒的时候回调用这个沙盒
    在这个方法中说清楚那些对象要归档怎么存储
 */
- (void)encodeWithCoder:(NSCoder *)encoder{
   
    [encoder encodeObject:self.access_token forKey:@"access_token"];
    [encoder encodeObject:self.expires_in forKey:@"expires_in"];
    [encoder encodeObject:self.uid forKey:@"uid"];
    
    [encoder encodeObject:self.created_time forKey:@"created_time"];
    [encoder encodeObject:self.name forKey:@"name"];
}

/**
 *  解档沙盒的对象的时候调用\
    说明沙盒中的属性怎么解档  也就是取出来
 */
- (instancetype)initWithCoder:(NSCoder *)decoder{
   
    if (self = [super init]) {
        
        self.access_token = [decoder decodeObjectForKey:@"access_token"];
        self.expires_in = [decoder decodeObjectForKey:@"expires_in"];
        self.uid = [decoder decodeObjectForKey:@"uid"];
        
        self.created_time = [decoder decodeObjectForKey:@"created_time"];
        self.name = [decoder decodeObjectForKey:@"name"];
        
        
    }
    return self;
}

@end
